package com.relytosoft.mizar.analyze.algorithm.base.controller;

import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.mizar.analyze.algorithm.base.service.UploadService;
import com.relytosoft.mizar.analyze.base.entity.pojo.base.BaseAlgoDataReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlFaceControlReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlStatusReq;
import com.relytosoft.mizar.analyze.base.entity.pojo.request.btdl.common.BtdlStructureControlReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;


/**
 * 接收算法推送数据
 *
 * @Author SunLi
 * @Date: 2022/5/16 11:55
 * @Version 1.0
 */

@RestController
@RequestMapping("/algo/upload")
@Api(tags = "接收算法推送数据接口")
public class UploadBaseController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(UploadBaseController.class);

    @Resource
    private UploadService uploadService;


    @ApiOperation(value = "实时数据接收")
    @PostMapping(value = "/data")
    public ResponseResult receiveData(HttpServletRequest request) {
        BaseAlgoDataReq dataReq = toDataReq(request);
        if (Objects.isNull(dataReq) || Objects.isNull(dataReq.getVideoSliceListObject())) {
            return ResponseResult.fail();
        }
        uploadService.receiveData(dataReq);
        return ResponseResult.ok();
    }


    @ApiOperation(value = "状态接收")
    @PostMapping("/status")
    public ResponseResult receiveStatus(HttpServletRequest request) {
        BtdlStatusReq statusReq = toStatusReq(request);
        if (Objects.isNull(statusReq)) {
            return ResponseResult.fail();
        }
        uploadService.receiveStatus(statusReq);
        return ResponseResult.ok();
    }

    @ApiOperation(value = "人脸布控告警接收")
    @PostMapping(value = "/face/alarm")
    public ResponseResult receiveFaceControlData(HttpServletRequest request) {
        List<BtdlFaceControlReq> btdlFaceControlReqs = toFaceControlReq(request);
        if (btdlFaceControlReqs.isEmpty()) {
            return ResponseResult.fail();
        }
        uploadService.receiveFaceControlData(btdlFaceControlReqs);
        return ResponseResult.ok();
    }

    @ApiOperation(value = "结构化布控告警接收")
    @PostMapping(value = "/structure/alarm")
    public ResponseResult receiveStructureControlData(HttpServletRequest request) {
        BtdlStructureControlReq btdlStructureControlReq = toStruControlReq(request);
        if (Objects.isNull(btdlStructureControlReq)) {
            return ResponseResult.fail();
        }
        uploadService.receiveStructureControlData(btdlStructureControlReq);
        return ResponseResult.ok();
    }

}
